package 笔试.腾讯;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/9/5-21:14
 * @version:1.0
 * @function:
 */
public class Main9005 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        int i = 0;
        while (i<n) arr[i] = scanner.nextInt();
        int temp = 0;
        for (i = 0; i < n; i++) {
            ArrayList<Integer> son = new ArrayList<>();
            for (int j = i; j < n; j++) {
                son.add(arr[j]);
                if (son.size() > 1)
                    if (isValid(son)) temp++;
            }
        }
        System.out.println(temp);
        scanner.close();
    }

    // 判断是否有效序列，默认长度>=2
    public static boolean isValid(List<Integer> a) {
        int n = a.size();
        for (int i = 1; i < n - 1; i++) {
            if (a.get(i) < a.get(0) || a.get(i) < a.get(n - 1))
                return false;
        }
        return true;
    }
}

